// pages/report/form.js
import areaCode from '../../utils/area_code.js';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sex:0,
    date: '2016-09-01',
    zhiwu: [
      {
        id: 0,
        name: '请选择职务'
      },
      {
        id: 1,
        name: '校长'
      },
      {
        id: 2,
        name: '副校长'
      },
      {
        id: 3,
        name: '主任'
      },
      {
        id: 4,
        name: '副主任'
      },
      {
        id: 5,
        name: '班主任'
      },
      {
        id: 6,
        name: '老师'
      },
      {
        id: 7,
        name: '学生'
      }
    ],
    zwIndex:0,
    minzu: [
      {
        id: 0,
        name: '汉族'
      },
      {
        id: 1,
        name: '藏族'
      },
      {
        id: 2,
        name: '苗族'
      },
      {
        id: 3,
        name: '蒙古族'
      },
      {
        id: 4,
        name: '布依族'
      },
      {
        id: 5,
        name: '回族'
      },
      {
        id: 6,
        name: '朝鲜族'
      }
    ],
    mzIndex:0,
    isShow: false,
    areaList: {
      province_list: areaCode.list.province_list,
      city_list: areaCode.list.city_list,
      county_list: areaCode.list.county_list
    },
    province: {
      name: '',
      code: ''
    },
    city: { name: '', code: ''},
    area: { name: '', code: ''},
    address_value: '180102',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  onClose() {
    this.setData({
      isShow: false
    })
  },

  bindPicker: function () {
    this.setData({
      isShow: true,
    });
  },

  getValues(v) {
    let data = v.detail.values;
    this.setData({
      province: data[0],
      city: data[1],
      area: data[2],
      isShow: false,
      address_value: data[2] ? data[2].code : '050100'
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  selSex:function(e){
    console.log(e)
    var sexVal = e.currentTarget.dataset.id;
    console.log(sexVal);
    _self.setData({
      sex:sexVal
    });
  },
  bindDateChange: function(e) {
    this.setData({
      date: e.detail.value
    })
  },
  bindzhiwu: function(e) {
    this.setData({
      zwIndex: e.detail.value
    })
  },
  save:function(e){
    let values = e.detail.value
    if (!values.real_name) {
      app.info('请填写真实姓名');
    }
    if (!values.zhiwu) {
      app.info('请选择职务');
    }
    if (!values.province) {
      app.info('请选择省');
    }
    if (!values.city) {
      app.info('请选择市');
    }
    if (!values.area) {
      app.info('请选择区');
    }
    if (!values.nation) {
      app.info('请填写民族');
    }
    if (!values.school) {
      app.info('请填写学校');
    }
    if (!values.grade) {
      app.info('请输入年级');
    }
    if (!values.mobile) {
      app.info('请输入电话');
    }

    let post = {
      real_name: values.real_name,
      gender: values.gender,
      birthday: this.data.date,
      province: this.data.province.code,
      city: this.data.city.code,
      area: this.data.area.code,
      nation: values.nation,
      school: values.school,
      duty: this.data.zhiwu[values.zhiwu].name,
      grade: values.grade,
      mobile: values.phone,
    }
    app.http.$ajax({
      url: 'user/profile',
      data: post
    }, {
        success: (res) => {
          app.success('绑定成功');
          setTimeout(() => {
            wx.switchTab({
              url: '/pages/index/index'
            })
          });
        }
      })
  },
 
})